<template>
  <div class="w-full p-20px pb-80px text-14px">
    <div
      class="w-full h-44px bg-white flex items-center justify-between px-20px"
    >
      <div>可提：¥{{ balance }}</div>
      <div class="text-[#F9363C]" @click="withdrawal()">全部提出</div>
    </div>
    <div class="mt-20px bg-white p-20px">
      <div class="mb-20px">提出金额 (元) (当前只支持整数提现)</div>
      <div class="pb-15px border-b">
        <van-cell-group inset>
          <van-field
            v-model="param.price"
            label="￥"
            type="digit"
            placeholder="请输入"
          />
        </van-cell-group>
      </div>

      <div class="mt-20px">提出方式：</div>
      <div>
        <van-radio-group v-model="radioChecked" @change="radioChange">
          <!-- <van-radio
            name="0"
            class="border-b mt-20px pb-20px justify-between"
            label-position="left"
            >WX</van-radio
          > -->
          <van-radio
            name="1"
            class="border-b mt-20px pb-20px justify-between"
            label-position="left"
            >ZFB</van-radio
          >
          <van-radio
            name="2"
            class="border-b mt-20px pb-20px justify-between"
            label-position="left"
            >YHK</van-radio
          >
        </van-radio-group>
      </div>
      <div class="mt-30px border-b pb-15px">
        <van-cell-group inset>
          <van-field
            v-model="param.password"
            type="password"
            label="登录密码"
            placeholder="请输入登录密码"
          />
        </van-cell-group>
      </div>
      <div
        @click="sumbit"
        class="mt-40px w-full h-49px flex justify-center items-center bg-[#2E95FF] rounded-5px text-white text-16px"
      >
        确认提出
      </div>
    </div>
  </div>
</template>
<script setup>
import { cashPage, cashDo } from "@/util/api";
import { showToast } from "vant";
import { useRouter } from "vue-router";
const radioChecked = ref("1");
const param = reactive({
  price: "",
  password: "",
  type: 1, //1微信2支付宝3银行卡
});
const router = useRouter();
const balance = ref("");
const getDate = async () => {
  const res = await cashPage();
  balance.value = res.msg.balance;
  //  console.log(res);
};
getDate();
const radioChange = (v) => {
  radioChecked.value = v;
  param.type = v;
  //  console.log(v);
};
//全部提出
const withdrawal = () => {
  param.price = balance.value;
};
//提现
const sumbit = async () => {
  param.type++;
  const res = await cashDo(param);
  showToast(res.msg);
  res.code == 1 ? router.go(-1) : "";
  param.type--;
};
</script>
<style scoped lang="scss">
:deep(.van-cell-group--inset) {
  margin: 0 !important;
}
:deep(.van-cell) {
  padding: 0 !important;
}
</style>
